package com.blog4j.article.api;

import com.blog4j.article.entity.LabelEntity;
import com.blog4j.article.service.LabelService;
import com.blog4j.article.vo.req.LabelListReqVo;
import com.blog4j.common.annotation.OperationLog;
import com.blog4j.common.enums.ModuleTypeEnum;
import com.blog4j.common.enums.OperationTypeEnum;
import com.blog4j.common.model.Result;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/7/2 21:19
 **/
@RestController
@RequestMapping("/api/label")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ApiLabelController {
    private final LabelService labelService;

    /**
     * 根据分类ID查询标签信息列表
     *
     * @param categoryId 分类ID
     * @return 标签信息列表
     */
    @OperationLog(operationType= OperationTypeEnum.QUERY,
            module= ModuleTypeEnum.ARTICLE,
            description = "根据分类ID查询标签信息列表")
    @GetMapping("/getByCategoryId/{categoryId}")
    public Result getByCategoryId(@PathVariable("categoryId") String categoryId) {
        List<LabelEntity> list = labelService.getByCategoryId(categoryId);
        return Result.ok(list);
    }

    /**
     * 根据创建者ID获取标签列表
     *
     * @return 标签列表
     */
    @OperationLog(operationType= OperationTypeEnum.QUERY,
            module= ModuleTypeEnum.ARTICLE,
            description = "根据创建者ID获取标签列表")
    @GetMapping("/getListByCreaterId")
    public Result getListByCreaterId() {
        List<LabelEntity> list = labelService.getListByCreaterId();
        return Result.ok(list);
    }

    /**
     * 标签列表查询
     *
     * @param reqVo 请求信息
     * @return 标签列表
     */
    @OperationLog(operationType= OperationTypeEnum.QUERY,
            module= ModuleTypeEnum.ARTICLE,
            description = "标签列表查询")
    @PostMapping("/list")
    public Result list(@RequestBody @Valid LabelListReqVo reqVo) {
        List<LabelEntity> list = labelService.getLabelList(reqVo);
        return Result.ok(new PageInfo<>(list));
    }

    /**
     * 根据标签ID查询详情信息
     *
     * @param labelId 标签ID
     * @return 详情信息
     */
    @OperationLog(operationType= OperationTypeEnum.QUERY,
            module= ModuleTypeEnum.ARTICLE,
            description = "根据标签ID查询详情信息")
    @GetMapping("/info/{labelId}")
    public Result info(@PathVariable("labelId") String labelId) {
        LabelEntity label = labelService.getById(labelId);
        return Result.ok(label);
    }
}
